package com.locationtracker.plus.ui.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import com.locationtracker.plus.R

class PermissionRemindDialog(context: Context, private val callback: () -> Unit) : Dialog(context) {

    init {
        // 拿到Dialog的Window, 修改Window的属性
        val window = window
        window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
        window.decorView.setPadding(0, 0, 0, 0)
        // 获取Window的LayoutParams
        setCancelable(false)
        setCanceledOnTouchOutside(false)
        val attributes = window.attributes
        attributes.width = WindowManager.LayoutParams.MATCH_PARENT
        attributes.gravity = Gravity.CENTER
        // 一定要重新设置, 才能生效
        window.attributes = attributes
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //初始化recyclerview
        val view = LayoutInflater.from(context).inflate(R.layout.dialog_permission_remind, null)
        view.findViewById<View>(R.id.understand).setOnClickListener {
            callback.invoke()
            dismiss()
        }
        setContentView(view)
    }
}
